<?php
abstract class DBDataAggregator implements Aggregatable, SetGetAble {
  protected $queryWrapper;
  protected $scafNode = NULL;
  
  protected abstract function buildScaffoldNode();
  
  public function getScaffoldNode() {
    if (is_null($this->scafNode)) $this->buildScaffoldNode();
    if (is_null($this->scafNode) || ($this->scafNode instanceof ScaffoldNode) == false) 
      throw new IncorrectDataAggregatorImplementation("method buildScaffoldNode() hasn't properly initialized scafNode");
    return $this->scafNode; 
  }
  
  public function refresh() {
    $this->queryWrapper->execute();
  }
  
  public function __get($pName) {
    return $this->queryWrapper->$pName;
  }
  
  public function __set($name, $value) {
    $this->queryWrapper->$name = $value;
  }
  
  public function getNumRows() {
    return $this->queryWrapper->count();
  }
}
